##########################################################################
######### Code for Online Appendix A
# Main text and online appendix
# 1. Getting data
# 2. Standardizing
# Data given in paper: Sample size average 

# Appendix Figures/Tables:
# A1: not done in code
# A2: Forest Plot 
# A3: p-curve 
# Tables A1-A2: not in code
# A4: Forest plot in elections 
# A5: Forest plot with unpublished work 
# A6: Comparing Estimates 

##########################################################################

rm(list = ls())
set.seed(30030)
options(scipen = 999) #disabling sci notation


library(ggplot2)
library(dplyr)
library(tidyverse)
library(ggrepel)
library(metaplus)
library(rmeta)
library(mvmeta)
library(meta)
library(metafor)
library(foreign)
library(readstata13)
library(lubridate)
library(dmetar) #see here for special instructions: https://bookdown.org/MathiasHarrer/Doing_Meta_Analysis_in_R/dmetar.html
library(xtable)
library(zoo)

#Set working directory
setwd("") #set working directory

##########################################################################
#### load study data ####

dat.berinsky <- read.dta13("Data/meta/berinsky2017.dta")
dat.berinskycces <- read.dta13("Data/meta/berinsky2017-cces.dta")
dat.clayton <- read.dta13("Data/meta/clayton2019.dta")
dat.huang1 <- read.delim("Data/meta/huang2017-1.tab")
dat.huang2 <- read.delim("Data/meta/huang2017-2.tab")
dat.nyhan1 <- read.dta13("Data/meta/nyhan2019-1.dta")
dat.nyhan2 <- readRDS("Data/meta/nyhan2019-2.rds")
dat.nyhanreifler1 <- read.dta13("Data/meta/nyhanreifler2010-1.dta")
dat.nyhanreifler2 <- read.dta13("Data/meta/nyhanreifler2010-2.dta")
dat.woodporter1 <- read.csv("Data/meta/elusive-tab 1.csv")

##########################################################################
#### standardized effect size function ####

#Adapted from Paluck et al

stand.result <- function( eff.type , u.s.d , ctrl.sd , n.t, n.c){
  ## All calculations taken from Cooper, Hedges, and Valentine (2009)
  
  # difference in differences
  if (eff.type == "d.i.d"){ 
    d <- round(u.s.d / ctrl.sd, digits = 3)
  }
  # difference in means
  else if (eff.type == "d.i.m"){
    d <- round(u.s.d / ctrl.sd, digits = 3)
  }
  # reporting of change of SDs in text:
  else if(eff.type == "d"){
    d <- u.s.d
  }
  
  # regression coefficient
  else if (eff.type == "reg.coef"){
    d <- round(u.s.d / ctrl.sd, digits = 3)
  }
  
  # t test
  else if (eff.type == "t.test"){
    d <- round(u.s.d * sqrt( (n.t + n.c ) / (n.t * n.c) ) , digits = 3)
  }
  # f.test
  else if (eff.type == "f.test"){
    d <- round(sqrt( ( u.s.d * (n.t + n.c) ) / (n.t * n.c) ), digits = 3)
  }
  # compute variance of the estimated effect size
  
  ust.var.d <- (((n.t + n.c)
                 / (n.t * n.c))
                +
                  ((d^2) / (2*(n.t + n.c)) )
  )
  # Apply hedge's g correction
  hedge.g <- 1 - (3
                  /
                    (4*(n.t + n.c -2 ) -1))
  
  var.d <- round((hedge.g^2) * ust.var.d, digits = 3)
  
  # standard error is the square root of variance
  st.err.g <- round(sqrt(var.d), digits = 3)
  
  # print everything out
  results <- c(d, var.d, st.err.g)
  
  col.names <- c("Standardized Effect" , "Variance of D" , "Standard Error of D")
  
  results.table <-data.frame(col.names, results)
  
  return(results.table)
}

##########################################################################
####  analyze data ####

#(a) berinsky 2017####
#from table 1, attentive sample (non-attentive not included in replication code)

dat.berinsky$outcome <- ifelse(dat.berinsky$w1_euth == "no",1,0) #code dichotomous with reject rumor as 1
n1 <- length(dat.berinsky$outcome)

berinsky.result1 <- stand.result(eff.type = "d.i.m",
                                 u.s.d = mean(dat.berinsky$outcome[dat.berinsky$treat==3],na.rm=T) - #rumor + non-partisan correction
                                   mean(dat.berinsky$outcome[dat.berinsky$treat==2],na.rm=T),  #rumor only
                                 ctrl.sd = sd(dat.berinsky$outcome[dat.berinsky$treat==2],na.rm=T),  #rumor only
                                 n.t = nrow(subset(dat.berinsky,dat.berinsky$treat==3)),
                                 n.c = nrow(subset(dat.berinsky,dat.berinsky$treat==2))
)

berinsky.result2 <- stand.result(eff.type = "d.i.m",
                                 u.s.d = mean(dat.berinsky$outcome[dat.berinsky$treat==4],na.rm=T) - #rumor + gop correction
                                   mean(dat.berinsky$outcome[dat.berinsky$treat==2],na.rm=T),  #rumor only
                                 ctrl.sd = sd(dat.berinsky$outcome[dat.berinsky$treat==2],na.rm=T),  #rumor only
                                 n.t = nrow(subset(dat.berinsky,dat.berinsky$treat==4)),
                                 n.c = nrow(subset(dat.berinsky,dat.berinsky$treat==2))
)

berinsky.result3 <- stand.result(eff.type = "d.i.m",
                                 u.s.d = mean(dat.berinsky$outcome[dat.berinsky$treat==5],na.rm=T) - #rumor + dem correction
                                   mean(dat.berinsky$outcome[dat.berinsky$treat==2],na.rm=T),  #rumor only
                                 ctrl.sd = sd(dat.berinsky$outcome[dat.berinsky$treat==2],na.rm=T),  #rumor only
                                 n.t = nrow(subset(dat.berinsky,dat.berinsky$treat==5)),
                                 n.c = nrow(subset(dat.berinsky,dat.berinsky$treat==2))
)

#from table 4

dat.berinskycces$outcome <- ifelse(dat.berinskycces$euth_w1 == "no ",1,0) #code dichotomous with reject rumor as 1
n2 <- length(dat.berinskycces$outcome)


berinsky.result4 <- stand.result(eff.type = "d.i.m",
                                 u.s.d = mean(dat.berinskycces$outcome[dat.berinskycces$randtreat=="c"],na.rm=T) - #rumor + correction
                                   mean(dat.berinskycces$outcome[dat.berinskycces$randtreat=="a"],na.rm=T),  #rumor only
                                 ctrl.sd = sd(dat.berinskycces$outcome[dat.berinskycces$randtreat=="a"],na.rm=T),  #rumor only
                                 n.t = nrow(subset(dat.berinskycces,dat.berinskycces$randtreat=="c")),
                                 n.c = nrow(subset(dat.berinskycces,dat.berinskycces$randtreat=="a"))
)

#(b) clayton et al 2019 ####

#main effects
#(using stata .do file/table 3 to generate values for stand.result function)
n3 <- 2994

clayton.result1 <- stand.result(eff.type = "reg.coef",
                                u.s.d = 0.0787899,  #warning (inverted for consistency)
                                ctrl.sd = 0.934205,  #control
                                n.t = 2530,
                                n.c = 2789)

clayton.result2 <- stand.result(eff.type = "reg.coef",
                                u.s.d = 0.2358087,  #disputed (inverted for consistency)
                                ctrl.sd = 0.934205,  #control
                                n.t = 1645,
                                n.c = 2789)

clayton.result3 <- stand.result(eff.type = "reg.coef",
                                u.s.d = 0.3435594,  #rated false (inverted for consistency)
                                ctrl.sd = 0.934205,  #control
                                n.t = 1707,
                                n.c = 2789)

#(c) einstein and glick 2015 ####

#NOT INCLUDED IN META-ANALYSIS
#"We therefore cannot fully parse whether the results presented below are attributable to the text describing the conspiracy, 
#the joint effect of the conspiracy and rebuttal, or even the rebuttal on its own" (p. 686)
#i.e. respondents were exposed to conspiracy and rebuttal simultaneously, so there is no true way to isolate correction effect

#(d) huang 2017 ####

dat.huang1$outcome1 <- 8 - dat.huang1$rumorabelief #invert rumor belief scale to be rumor disbelief scale (for consistency)
dat.huang1$outcome2 <- 8 - dat.huang1$rumorbbelief
dat.huang2$outcome1 <- 8 - dat.huang2$rumorabelief
dat.huang2$outcome2 <- 8 - dat.huang2$rumorbbelief

n4 <- length(dat.huang1$outcome1)
n5 <- length(dat.huang1$outcome2)
n6 <- length(dat.huang2$outcome1)
n7 <- length(dat.huang2$outcome2)

#STUDY 1

huang.result1 <- stand.result(eff.type = "d.i.m",
                              u.s.d = mean(dat.huang1$outcome1[dat.huang1$rebuta==1],na.rm=T) - #rumor a/b + rebuttal a
                                mean(dat.huang1$outcome1[dat.huang1$rumor==1],na.rm=T),  #rumor a/b only
                              ctrl.sd = sd(dat.huang1$outcome1[dat.huang1$rumor==1],na.rm=T),  #rumor a/b only
                              n.t = nrow(subset(dat.huang1,dat.huang1$rebuta==1)),
                              n.c = nrow(subset(dat.huang1,dat.huang1$rumor==1))
)

huang.result2 <- stand.result(eff.type = "d.i.m",
                              u.s.d = mean(dat.huang1$outcome2[dat.huang1$rebutb==1],na.rm=T) - #rumor a/b + rebuttal b
                                mean(dat.huang1$outcome2[dat.huang1$rumor==1],na.rm=T),  #rumor a/b only
                              ctrl.sd = sd(dat.huang1$outcome2[dat.huang1$rumor==1],na.rm=T),  #rumor a/b only
                              n.t = nrow(subset(dat.huang1,dat.huang1$rebutb==1)),
                              n.c = nrow(subset(dat.huang1,dat.huang1$rumor==1))
)

#STUDY 2

huang.result3 <- stand.result(eff.type = "d.i.m",
                              u.s.d = mean(dat.huang2$outcome1[dat.huang2$rebuta==1],na.rm=T) - #rumor a/b + rebuttal a
                                mean(dat.huang2$outcome1[dat.huang2$rumor==1],na.rm=T),  #rumor a/b only
                              ctrl.sd = sd(dat.huang2$outcome1[dat.huang2$rumor==1],na.rm=T),  #rumor a/b only
                              n.t = nrow(subset(dat.huang2,dat.huang2$rebuta==1)),
                              n.c = nrow(subset(dat.huang2,dat.huang2$rumor==1))
)

huang.result4 <- stand.result(eff.type = "d.i.m",
                              u.s.d = mean(dat.huang2$outcome2[dat.huang2$rebutb==1],na.rm=T) - #rumor a/b + rebuttal b
                                mean(dat.huang2$outcome2[dat.huang2$rumor==1],na.rm=T),  #rumor a/b only
                              ctrl.sd = sd(dat.huang2$outcome2[dat.huang2$rumor==1],na.rm=T),  #rumor a/b only
                              n.t = nrow(subset(dat.huang2,dat.huang2$rebutb==1)),
                              n.c = nrow(subset(dat.huang2,dat.huang2$rumor==1)) 
)


#(e) nyhan et al 2019 ####

#study 1 (see table 1)

dat.nyhan1$outcome <- 6 - dat.nyhan1$crimechange #create misinformation disbelief scale (for consistency)
n8 <- length(dat.nyhan1$outcome)

nyhanetal.result1 <- stand.result(eff.type = "reg.coef",
                                  u.s.d = summary(lm(outcome ~ correction, 
                                                     dat=subset(dat.nyhan1, turk==0 & (clintonsupport==1 | trumpsupport == 1))))$coefficients[2], #fact check
                                  ctrl.sd = sd(dat.nyhan1$outcome[dat.nyhan1$correction==0 & dat.nyhan1$turk==0],na.rm=T),  #no fact check
                                  n.t = nrow(subset(dat.nyhan1,dat.nyhan1$correction==1 & dat.nyhan1$turk==0)),
                                  n.c = nrow(subset(dat.nyhan1,dat.nyhan1$correction==0 & dat.nyhan1$turk==0)) )

nyhanetal.result2 <- stand.result(eff.type = "reg.coef",
                                  u.s.d = summary(lm(outcome ~ correction, 
                                                     dat=subset(dat.nyhan1, turk==1 & (clintonsupport==1 | trumpsupport == 1))))$coefficients[2], #fact check
                                  ctrl.sd = sd(dat.nyhan1$outcome[dat.nyhan1$correction==0 & dat.nyhan1$turk==1],na.rm=T),  #no fact check
                                  n.t = nrow(subset(dat.nyhan1,dat.nyhan1$correction==1 & dat.nyhan1$turk==1)),
                                  n.c = nrow(subset(dat.nyhan1,dat.nyhan1$correction==0 & dat.nyhan1$turk==1)) )

#study 2 

dat.nyhan2$outcome <- 6 - dat.nyhan2$ans #create misinformation disbelief scale (for consistency)
n9 <- length(dat.nyhan2$outcome)

nyhanetal.result3 <- stand.result(eff.type = "reg.coef",
                                  u.s.d = summary(lm(outcome ~ ifelse(corr_cond == "Correction",1,0), 
                                                     dat=subset(dat.nyhan2)))$coefficients[2], #fact check
                                  ctrl.sd = sd(dat.nyhan2$outcome[ifelse(dat.nyhan2$corr_cond == "Correction",1,0) == 0],na.rm=T),  #no fact check
                                  n.t = nrow(subset(dat.nyhan2,ifelse(dat.nyhan2$corr_cond == "Correction",1,0) == 1)),
                                  n.c = nrow(subset(dat.nyhan2,ifelse(dat.nyhan2$corr_cond == "Correction",1,0) == 0)) )

#(f) nyhan and reifler 2010 ####

dat.nyhanreifler1$outcome <- NA #create misinformation disbelief scale (for consistency)
dat.nyhanreifler1$outcome[dat.nyhanreifler1$wmds == "Strongly agree"] <- 1
dat.nyhanreifler1$outcome[dat.nyhanreifler1$wmds == "Somewhat agree"] <- 2
dat.nyhanreifler1$outcome[dat.nyhanreifler1$wmds == "Neither agree nor disagree"] <- 3
dat.nyhanreifler1$outcome[dat.nyhanreifler1$wmds == "Somewhat disagree"] <- 4
dat.nyhanreifler1$outcome[dat.nyhanreifler1$wmds == "Strongly disagree"] <- 5

dat.nyhanreifler2$outcome1 <- 6 - dat.nyhanreifler2$iraqwmd #create misinformation disbelief scale (for consistency)
dat.nyhanreifler2$outcome2 <- 6 - dat.nyhanreifler2$taxcutrev
dat.nyhanreifler2$outcome3 <- 6 - dat.nyhanreifler2$stemcellban

n10 <- length(dat.nyhanreifler1$outcome)
n11 <- length(dat.nyhanreifler2$outcome1)
n13 <-  length(dat.nyhanreifler2$outcome3)

nyhanreifler.result1 <- stand.result(eff.type = "reg.coef",
                                     u.s.d = summary(lm(outcome ~ iraqcorr + ideolcen + know + ms, dat=dat.nyhanreifler1))$coefficients[2], #correction
                                     ctrl.sd = sd(dat.nyhanreifler1$outcome[dat.nyhanreifler1$iraqcorr==0],na.rm=T),  #no correction
                                     n.t = nrow(subset(dat.nyhanreifler1,dat.nyhanreifler1$iraqcorr==1)),
                                     n.c = nrow(subset(dat.nyhanreifler1,dat.nyhanreifler1$iraqcorr==0)) 
)

nyhanreifler.result2 <- stand.result(eff.type = "reg.coef",
                                     u.s.d = summary(lm(outcome1 ~ iraqcorr + ideolcen + know, dat=dat.nyhanreifler2))$coefficients[2], #wmd correction
                                     ctrl.sd = sd(dat.nyhanreifler2$outcome1[dat.nyhanreifler2$iraqcorr==0],na.rm=T),  #no correction
                                     n.t = nrow(subset(dat.nyhanreifler2,dat.nyhanreifler2$iraqcorr==1)),
                                     n.c = nrow(subset(dat.nyhanreifler2,dat.nyhanreifler2$iraqcorr==0)) 
)

nyhanreifler.result3 <- stand.result(eff.type = "reg.coef",
                                     u.s.d = summary(lm(outcome2 ~ taxcutcorr + ideolcen + know, dat=dat.nyhanreifler2))$coefficients[2], #tax correction
                                     ctrl.sd = sd(dat.nyhanreifler2$outcome2[dat.nyhanreifler2$taxcutcorr==0],na.rm=T),  #no correction
                                     n.t = nrow(subset(dat.nyhanreifler2,dat.nyhanreifler2$taxcutcorr==1)),
                                     n.c = nrow(subset(dat.nyhanreifler2,dat.nyhanreifler2$taxcutcorr==0)) 
)

nyhanreifler.result4 <- stand.result(eff.type = "reg.coef",
                                     u.s.d = summary(lm(outcome3 ~ sccorr + ideolcen + know, dat=dat.nyhanreifler2))$coefficients[2], #stem cell correction
                                     ctrl.sd = sd(dat.nyhanreifler2$outcome3[dat.nyhanreifler2$sccorr==0],na.rm=T),  #no correction
                                     n.t = nrow(subset(dat.nyhanreifler2,dat.nyhanreifler2$sccorr==1)),
                                     n.c = nrow(subset(dat.nyhanreifler2,dat.nyhanreifler2$sccorr==0)) 
)


#(g) wood and porter 2019 ####

dat.woodporter1$outcome <- 6 - dat.woodporter1$ans #create misinformation disbelief scale (for consistency)
n14 <- length(dat.woodporter1$outcome)

#STUDY 1
#(note results are numbered in accordance with their order of appearance in Table 1)

woodporter.result01 <- stand.result(eff.type = "reg.coef",
                                    u.s.d = summary(lm(outcome ~ ifelse(corr=="Correction",1,0), 
                                                       dat=subset(dat.woodporter1,dat.woodporter1$item == "Gun violence at all time high (Clinton)(1)")))$coefficients[2], #item 1 correction
                                    ctrl.sd = sd(dat.woodporter1$outcome[dat.woodporter1$corr=="No Correction" & dat.woodporter1$item == "Gun violence at all time high (Clinton)(1)"],na.rm=T),  #no correction
                                    n.t = nrow(subset(dat.woodporter1,dat.woodporter1$corr=="Correction" & dat.woodporter1$item == "Gun violence at all time high (Clinton)(1)")),
                                    n.c = nrow(subset(dat.woodporter1,dat.woodporter1$corr=="No Correction" & dat.woodporter1$item == "Gun violence at all time high (Clinton)(1)")) 
)

woodporter.result02 <- stand.result(eff.type = "reg.coef",
                                    u.s.d = summary(lm(outcome ~ ifelse(corr=="Correction",1,0), 
                                                       dat=subset(dat.woodporter1,dat.woodporter1$item == "Most prisoners serving drug sentences (Obama)(1)")))$coefficients[2], #item 2 correction
                                    ctrl.sd = sd(dat.woodporter1$outcome[dat.woodporter1$corr=="No Correction" & dat.woodporter1$item == "Most prisoners serving drug sentences (Obama)(1)"],na.rm=T),  #no correction
                                    n.t = nrow(subset(dat.woodporter1,dat.woodporter1$corr=="Correction" & dat.woodporter1$item == "Most prisoners serving drug sentences (Obama)(1)")),
                                    n.c = nrow(subset(dat.woodporter1,dat.woodporter1$corr=="No Correction" & dat.woodporter1$item == "Most prisoners serving drug sentences (Obama)(1)")) 
)


woodporter.result03 <- NA   #more jobs in solar than oil (Clinton) does not exist for study 1 despite indication in Table 1 

woodporter.result04 <- stand.result(eff.type = "reg.coef",
                                    u.s.d = summary(lm(outcome ~ ifelse(corr=="Correction",1,0), 
                                                       dat=subset(dat.woodporter1,dat.woodporter1$item == "Workers pay more tax than financiers (Clinton)(1)")))$coefficients[2], #item 4 correction
                                    ctrl.sd = sd(dat.woodporter1$outcome[dat.woodporter1$corr=="No Correction" & dat.woodporter1$item == "Workers pay more tax than financiers (Clinton)(1)"],na.rm=T),  #no correction
                                    n.t = nrow(subset(dat.woodporter1,dat.woodporter1$corr=="Correction" & dat.woodporter1$item == "Workers pay more tax than financiers (Clinton)(1)")),
                                    n.c = nrow(subset(dat.woodporter1,dat.woodporter1$corr=="No Correction" & dat.woodporter1$item == "Workers pay more tax than financiers (Clinton)(1)")) 
)

woodporter.result05 <- stand.result(eff.type = "reg.coef",
                                    u.s.d = summary(lm(outcome ~ ifelse(corr=="Correction",1,0), 
                                                       dat=subset(dat.woodporter1,dat.woodporter1$item == "Discrimin. sole cause wage gap (Obama)(1)")))$coefficients[2], #item 5 correction
                                    ctrl.sd = sd(dat.woodporter1$outcome[dat.woodporter1$corr=="No Correction" & dat.woodporter1$item == "Discrimin. sole cause wage gap (Obama)(1)"],na.rm=T),  #no correction
                                    n.t = nrow(subset(dat.woodporter1,dat.woodporter1$corr=="Correction" & dat.woodporter1$item == "Discrimin. sole cause wage gap (Obama)(1)")),
                                    n.c = nrow(subset(dat.woodporter1,dat.woodporter1$corr=="No Correction" & dat.woodporter1$item == "Discrimin. sole cause wage gap (Obama)(1)")) 
)

woodporter.result06 <- stand.result(eff.type = "reg.coef",
                                    u.s.d = summary(lm(outcome ~ ifelse(corr=="Correction",1,0), 
                                                       dat=subset(dat.woodporter1,dat.woodporter1$item == "Obama cuts defense spending (Rubio)(1)")))$coefficients[2], #item 6 correction
                                    ctrl.sd = sd(dat.woodporter1$outcome[dat.woodporter1$corr=="No Correction" & dat.woodporter1$item == "Obama cuts defense spending (Rubio)(1)"],na.rm=T),  #no correction
                                    n.t = nrow(subset(dat.woodporter1,dat.woodporter1$corr=="Correction" & dat.woodporter1$item == "Obama cuts defense spending (Rubio)(1)")),
                                    n.c = nrow(subset(dat.woodporter1,dat.woodporter1$corr=="No Correction" & dat.woodporter1$item == "Obama cuts defense spending (Rubio)(1)")) 
)

woodporter.result07 <- stand.result(eff.type = "reg.coef",
                                    u.s.d = summary(lm(outcome ~ ifelse(corr=="Correction",1,0), 
                                                       dat=subset(dat.woodporter1,dat.woodporter1$item == "Undocumented disprop. criminal (Trump)(1)")))$coefficients[2], #item 7 correction
                                    ctrl.sd = sd(dat.woodporter1$outcome[dat.woodporter1$corr=="No Correction" & dat.woodporter1$item == "Undocumented disprop. criminal (Trump)(1)"],na.rm=T),  #no correction
                                    n.t = nrow(subset(dat.woodporter1,dat.woodporter1$corr=="Correction" & dat.woodporter1$item == "Undocumented disprop. criminal (Trump)(1)")),
                                    n.c = nrow(subset(dat.woodporter1,dat.woodporter1$corr=="No Correction" & dat.woodporter1$item == "Undocumented disprop. criminal (Trump)(1)")) 
)

woodporter.result08 <- stand.result(eff.type = "reg.coef",
                                    u.s.d = summary(lm(outcome ~ ifelse(corr=="Correction",1,0), 
                                                       dat=subset(dat.woodporter1,dat.woodporter1$item == "Surge in killings of police officers (Cruz)(1)")))$coefficients[2], #item 8 correction
                                    ctrl.sd = sd(dat.woodporter1$outcome[dat.woodporter1$corr=="No Correction" & dat.woodporter1$item == "Surge in killings of police officers (Cruz)(1)"],na.rm=T),  #no correction
                                    n.t = nrow(subset(dat.woodporter1,dat.woodporter1$corr=="Correction" & dat.woodporter1$item == "Surge in killings of police officers (Cruz)(1)")),
                                    n.c = nrow(subset(dat.woodporter1,dat.woodporter1$corr=="No Correction" & dat.woodporter1$item == "Surge in killings of police officers (Cruz)(1)")) 
)

woodporter.result09 <- stand.result(eff.type = "reg.coef",
                                    u.s.d = summary(lm(outcome ~ ifelse(corr=="Correction",1,0), 
                                                       dat=subset(dat.woodporter1,dat.woodporter1$item == "US taxes highest in world (Trump)(1)")))$coefficients[2], #item 9 correction
                                    ctrl.sd = sd(dat.woodporter1$outcome[dat.woodporter1$corr=="No Correction" & dat.woodporter1$item == "US taxes highest in world (Trump)(1)"],na.rm=T),  #no correction
                                    n.t = nrow(subset(dat.woodporter1,dat.woodporter1$corr=="Correction" & dat.woodporter1$item == "US taxes highest in world (Trump)(1)")),
                                    n.c = nrow(subset(dat.woodporter1,dat.woodporter1$corr=="No Correction" & dat.woodporter1$item == "US taxes highest in world (Trump)(1)")) 
)

#STUDY 2

woodporter.result10 <- stand.result(eff.type = "reg.coef",
                                    u.s.d = summary(lm(outcome ~ ifelse(corr=="Correction",1,0), 
                                                       dat=subset(dat.woodporter1,dat.woodporter1$item == "Obama passed TARP (Palin)(2)")))$coefficients[2], #item 10 correction
                                    ctrl.sd = sd(dat.woodporter1$outcome[dat.woodporter1$corr=="No Correction" & dat.woodporter1$item == "Obama passed TARP (Palin)(2)"],na.rm=T),  #no correction
                                    n.t = nrow(subset(dat.woodporter1,dat.woodporter1$corr=="Correction" & dat.woodporter1$item == "Obama passed TARP (Palin)(2)")),
                                    n.c = nrow(subset(dat.woodporter1,dat.woodporter1$corr=="No Correction" & dat.woodporter1$item == "Obama passed TARP (Palin)(2)")) 
)

woodporter.result11 <- stand.result(eff.type = "reg.coef",
                                    u.s.d = summary(lm(outcome ~ ifelse(corr=="Correction",1,0), 
                                                       dat=subset(dat.woodporter1,dat.woodporter1$item == "Obama passed TARP (Obama)(2)")))$coefficients[2], #item 11 correction
                                    ctrl.sd = sd(dat.woodporter1$outcome[dat.woodporter1$corr=="No Correction" & dat.woodporter1$item == "Obama passed TARP (Obama)(2)"],na.rm=T),  #no correction
                                    n.t = nrow(subset(dat.woodporter1,dat.woodporter1$corr=="Correction" & dat.woodporter1$item == "Obama passed TARP (Obama)(2)")),
                                    n.c = nrow(subset(dat.woodporter1,dat.woodporter1$corr=="No Correction" & dat.woodporter1$item == "Obama passed TARP (Obama)(2)")) 
)

woodporter.result12 <- stand.result(eff.type = "reg.coef",
                                    u.s.d = summary(lm(outcome ~ ifelse(corr=="Correction",1,0), 
                                                       dat=subset(dat.woodporter1,dat.woodporter1$item == "Obama accomodates undocumented (Cruz)(2)")))$coefficients[2], #item 12 correction
                                    ctrl.sd = sd(dat.woodporter1$outcome[dat.woodporter1$corr=="No Correction" & dat.woodporter1$item == "Obama accomodates undocumented (Cruz)(2)"],na.rm=T),  #no correction
                                    n.t = nrow(subset(dat.woodporter1,dat.woodporter1$corr=="Correction" & dat.woodporter1$item == "Obama accomodates undocumented (Cruz)(2)")),
                                    n.c = nrow(subset(dat.woodporter1,dat.woodporter1$corr=="No Correction" & dat.woodporter1$item == "Obama accomodates undocumented (Cruz)(2)")) 
)

woodporter.result13 <- stand.result(eff.type = "reg.coef",
                                    u.s.d = summary(lm(outcome ~ ifelse(corr=="Correction",1,0), 
                                                       dat=subset(dat.woodporter1,dat.woodporter1$item == "Obama accomodates undocumented (Gutiérrez)(2)")))$coefficients[2], #item 13 correction
                                    ctrl.sd = sd(dat.woodporter1$outcome[dat.woodporter1$corr=="No Correction" & dat.woodporter1$item == "Obama accomodates undocumented (Gutiérrez)(2)"],na.rm=T),  #no correction
                                    n.t = nrow(subset(dat.woodporter1,dat.woodporter1$corr=="Correction" & dat.woodporter1$item == "Obama accomodates undocumented (Gutiérrez)(2)")),
                                    n.c = nrow(subset(dat.woodporter1,dat.woodporter1$corr=="No Correction" & dat.woodporter1$item == "Obama accomodates undocumented (Gutiérrez)(2)")) 
)

woodporter.result14 <- stand.result(eff.type = "reg.coef",
                                    u.s.d = summary(lm(outcome ~ ifelse(corr=="Correction",1,0), 
                                                       dat=subset(dat.woodporter1,dat.woodporter1$item == "Spiraling teen pregnancy rate (Carson)(2)")))$coefficients[2], #item 14 correction
                                    ctrl.sd = sd(dat.woodporter1$outcome[dat.woodporter1$corr=="No Correction" & dat.woodporter1$item == "Spiraling teen pregnancy rate (Carson)(2)"],na.rm=T),  #no correction
                                    n.t = nrow(subset(dat.woodporter1,dat.woodporter1$corr=="Correction" & dat.woodporter1$item == "Spiraling teen pregnancy rate (Carson)(2)")),
                                    n.c = nrow(subset(dat.woodporter1,dat.woodporter1$corr=="No Correction" & dat.woodporter1$item == "Spiraling teen pregnancy rate (Carson)(2)")) 
)

woodporter.result15 <- stand.result(eff.type = "reg.coef",
                                    u.s.d = summary(lm(outcome ~ ifelse(corr=="Correction",1,0), 
                                                       dat=subset(dat.woodporter1,dat.woodporter1$item == "Spiraling teen pregnancy rate (Lee)(2)")))$coefficients[2], #item 15 correction
                                    ctrl.sd = sd(dat.woodporter1$outcome[dat.woodporter1$corr=="No Correction" & dat.woodporter1$item == "Spiraling teen pregnancy rate (Lee)(2)"],na.rm=T),  #no correction
                                    n.t = nrow(subset(dat.woodporter1,dat.woodporter1$corr=="Correction" & dat.woodporter1$item == "Spiraling teen pregnancy rate (Lee)(2)")),
                                    n.c = nrow(subset(dat.woodporter1,dat.woodporter1$corr=="No Correction" & dat.woodporter1$item == "Spiraling teen pregnancy rate (Lee)(2)")) 
)

woodporter.result16 <- stand.result(eff.type = "reg.coef",
                                    u.s.d = summary(lm(outcome ~ ifelse(corr=="Correction",1,0), 
                                                       dat=subset(dat.woodporter1,dat.woodporter1$item == "China holds majority of US debt (Romney)(2)")))$coefficients[2], #item 16 correction
                                    ctrl.sd = sd(dat.woodporter1$outcome[dat.woodporter1$corr=="No Correction" & dat.woodporter1$item == "China holds majority of US debt (Romney)(2)"],na.rm=T),  #no correction
                                    n.t = nrow(subset(dat.woodporter1,dat.woodporter1$corr=="Correction" & dat.woodporter1$item == "China holds majority of US debt (Romney)(2)")),
                                    n.c = nrow(subset(dat.woodporter1,dat.woodporter1$corr=="No Correction" & dat.woodporter1$item == "China holds majority of US debt (Romney)(2)")) 
)

woodporter.result17 <- stand.result(eff.type = "reg.coef",
                                    u.s.d = summary(lm(outcome ~ ifelse(corr=="Correction",1,0), 
                                                       dat=subset(dat.woodporter1,dat.woodporter1$item == "China holds majority of US debt (Obama)(2)")))$coefficients[2], #item 17 correction
                                    ctrl.sd = sd(dat.woodporter1$outcome[dat.woodporter1$corr=="No Correction" & dat.woodporter1$item == "China holds majority of US debt (Obama)(2)"],na.rm=T),  #no correction
                                    n.t = nrow(subset(dat.woodporter1,dat.woodporter1$corr=="Correction" & dat.woodporter1$item == "China holds majority of US debt (Obama)(2)")),
                                    n.c = nrow(subset(dat.woodporter1,dat.woodporter1$corr=="No Correction" & dat.woodporter1$item == "China holds majority of US debt (Obama)(2)")) 
)

woodporter.result18 <- stand.result(eff.type = "reg.coef",
                                    u.s.d = summary(lm(outcome ~ ifelse(corr=="Correction",1,0), 
                                                       dat=subset(dat.woodporter1,dat.woodporter1$item == "Whites imminently a minority (Graham)(2)")))$coefficients[2], #item 18 correction
                                    ctrl.sd = sd(dat.woodporter1$outcome[dat.woodporter1$corr=="No Correction" & dat.woodporter1$item == "Whites imminently a minority (Graham)(2)"],na.rm=T),  #no correction
                                    n.t = nrow(subset(dat.woodporter1,dat.woodporter1$corr=="Correction" & dat.woodporter1$item == "Whites imminently a minority (Graham)(2)")),
                                    n.c = nrow(subset(dat.woodporter1,dat.woodporter1$corr=="No Correction" & dat.woodporter1$item == "Whites imminently a minority (Graham)(2)")) 
)

woodporter.result19 <- stand.result(eff.type = "reg.coef",
                                    u.s.d = summary(lm(outcome ~ ifelse(corr=="Correction",1,0), 
                                                       dat=subset(dat.woodporter1,dat.woodporter1$item == "Whites imminently a minority (Longoria)(2)")))$coefficients[2], #item 19 correction
                                    ctrl.sd = sd(dat.woodporter1$outcome[dat.woodporter1$corr=="No Correction" & dat.woodporter1$item == "Whites imminently a minority (Longoria)(2)"],na.rm=T),  #no correction
                                    n.t = nrow(subset(dat.woodporter1,dat.woodporter1$corr=="Correction" & dat.woodporter1$item == "Whites imminently a minority (Longoria)(2)")),
                                    n.c = nrow(subset(dat.woodporter1,dat.woodporter1$corr=="No Correction" & dat.woodporter1$item == "Whites imminently a minority (Longoria)(2)")) 
)

woodporter.result20 <- stand.result(eff.type = "reg.coef",
                                    u.s.d = summary(lm(outcome ~ ifelse(corr=="Correction",1,0), 
                                                       dat=subset(dat.woodporter1,dat.woodporter1$item == "Spiraling Chicago gun violence (LaPierre)(2)")))$coefficients[2], #item 20 correction
                                    ctrl.sd = sd(dat.woodporter1$outcome[dat.woodporter1$corr=="No Correction" & dat.woodporter1$item == "Spiraling Chicago gun violence (LaPierre)(2)"],na.rm=T),  #no correction
                                    n.t = nrow(subset(dat.woodporter1,dat.woodporter1$corr=="Correction" & dat.woodporter1$item == "Spiraling Chicago gun violence (LaPierre)(2)")),
                                    n.c = nrow(subset(dat.woodporter1,dat.woodporter1$corr=="No Correction" & dat.woodporter1$item == "Spiraling Chicago gun violence (LaPierre)(2)")) 
)

woodporter.result21 <- stand.result(eff.type = "reg.coef",
                                    u.s.d = summary(lm(outcome ~ ifelse(corr=="Correction",1,0), 
                                                       dat=subset(dat.woodporter1,dat.woodporter1$item == "Spiraling Chicago gun violence (Obama)(2)")))$coefficients[2], #item 21 correction
                                    ctrl.sd = sd(dat.woodporter1$outcome[dat.woodporter1$corr=="No Correction" & dat.woodporter1$item == "Spiraling Chicago gun violence (Obama)(2)"],na.rm=T),  #no correction
                                    n.t = nrow(subset(dat.woodporter1,dat.woodporter1$corr=="Correction" & dat.woodporter1$item == "Spiraling Chicago gun violence (Obama)(2)")),
                                    n.c = nrow(subset(dat.woodporter1,dat.woodporter1$corr=="No Correction" & dat.woodporter1$item == "Spiraling Chicago gun violence (Obama)(2)")) 
)

woodporter.result22 <- stand.result(eff.type = "reg.coef",
                                    u.s.d = summary(lm(outcome ~ ifelse(corr=="Correction",1,0), 
                                                       dat=subset(dat.woodporter1,dat.woodporter1$item == "Spiraling abortion rate (Ryan)(2)")))$coefficients[2], #item 22 correction
                                    ctrl.sd = sd(dat.woodporter1$outcome[dat.woodporter1$corr=="No Correction" & dat.woodporter1$item == "Spiraling abortion rate (Ryan)(2)"],na.rm=T),  #no correction
                                    n.t = nrow(subset(dat.woodporter1,dat.woodporter1$corr=="Correction" & dat.woodporter1$item == "Spiraling abortion rate (Ryan)(2)")),
                                    n.c = nrow(subset(dat.woodporter1,dat.woodporter1$corr=="No Correction" & dat.woodporter1$item == "Spiraling abortion rate (Ryan)(2)")) 
)

woodporter.result23 <- stand.result(eff.type = "reg.coef",
                                    u.s.d = summary(lm(outcome ~ ifelse(corr=="Correction",1,0), 
                                                       dat=subset(dat.woodporter1,dat.woodporter1$item == "Spiraling abortion rate (Obama)(2)")))$coefficients[2], #item 23 correction
                                    ctrl.sd = sd(dat.woodporter1$outcome[dat.woodporter1$corr=="No Correction" & dat.woodporter1$item == "Spiraling abortion rate (Obama)(2)"],na.rm=T),  #no correction
                                    n.t = nrow(subset(dat.woodporter1,dat.woodporter1$corr=="Correction" & dat.woodporter1$item == "Spiraling abortion rate (Obama)(2)")),
                                    n.c = nrow(subset(dat.woodporter1,dat.woodporter1$corr=="No Correction" & dat.woodporter1$item == "Spiraling abortion rate (Obama)(2)")) 
)

woodporter.result24 <- stand.result(eff.type = "reg.coef",
                                    u.s.d = summary(lm(outcome ~ ifelse(corr=="Correction",1,0), 
                                                       dat=subset(dat.woodporter1,dat.woodporter1$item == "Obama restricts drones' use (Graham)(2)")))$coefficients[2], #item 24 correction
                                    ctrl.sd = sd(dat.woodporter1$outcome[dat.woodporter1$corr=="No Correction" & dat.woodporter1$item == "Obama restricts drones' use (Graham)(2)"],na.rm=T),  #no correction
                                    n.t = nrow(subset(dat.woodporter1,dat.woodporter1$corr=="Correction" & dat.woodporter1$item == "Obama restricts drones' use (Graham)(2)")),
                                    n.c = nrow(subset(dat.woodporter1,dat.woodporter1$corr=="No Correction" & dat.woodporter1$item == "Obama restricts drones' use (Graham)(2)")) 
)

woodporter.result25 <- stand.result(eff.type = "reg.coef",
                                    u.s.d = summary(lm(outcome ~ ifelse(corr=="Correction",1,0), 
                                                       dat=subset(dat.woodporter1,dat.woodporter1$item == "Obama restricts drones' use (Obama)(2)")))$coefficients[2], #item 25 correction
                                    ctrl.sd = sd(dat.woodporter1$outcome[dat.woodporter1$corr=="No Correction" & dat.woodporter1$item == "Obama restricts drones' use (Obama)(2)"],na.rm=T),  #no correction
                                    n.t = nrow(subset(dat.woodporter1,dat.woodporter1$corr=="Correction" & dat.woodporter1$item == "Obama restricts drones' use (Obama)(2)")),
                                    n.c = nrow(subset(dat.woodporter1,dat.woodporter1$corr=="No Correction" & dat.woodporter1$item == "Obama restricts drones' use (Obama)(2)")) 
)

#(h) badrinathan, chauchard, and flynn (working paper)####

badrinathan.result1 <- stand.result(eff.type = "reg.coef",
                                    u.s.d = 0.104, #inverted for consistency  
                                    ctrl.sd = 1.096,  #overall sd of outcome
                                    n.t = round(5104*0.75,1), #estimate: 75% of sample (see working paper p. 11)
                                    n.c = round(5104*0.25,1)) #estimate: 25% of sample (see working paper p. 11)

badrinathan.result2 <- stand.result(eff.type = "reg.coef",
                                    u.s.d = 0.190,  #inverted for consistency   
                                    ctrl.sd = 0.949,  #overall sd of outcome
                                    n.t = round(5103*0.75,1), #estimate: 75% of sample (see working paper p. 11)
                                    n.c = round(5103*0.25,1)) #estimate: 25% of sample (see working paper p. 11)

badrinathan.result3 <- stand.result(eff.type = "reg.coef",
                                    u.s.d = 0.448,  #inverted for consistency   
                                    ctrl.sd = 1.058,  #overall sd of outcome
                                    n.t = round(5061*0.75,1), #estimate: 75% of sample (see working paper p. 11)
                                    n.c = round(5061*0.25,1)) #estimate: 25% of sample (see working paper p. 11)

badrinathan.result4 <- stand.result(eff.type = "reg.coef",
                                    u.s.d = 0.106,  #inverted for consistency   
                                    ctrl.sd = 1.061,  #overall sd of outcome
                                    n.t = round(5099*0.75,1), #estimate: 75% of sample (see working paper p. 11)
                                    n.c = round(5099*0.25,1)) #estimate: 25% of sample (see working paper p. 11)

badrinathan.result5 <- stand.result(eff.type = "reg.coef",
                                    u.s.d = 0.024,  #inverted for consistency   
                                    ctrl.sd = 1.014,  #overall sd of outcome
                                    n.t = round(5136*0.75,1), #estimate: 75% of sample (see working paper p. 11)
                                    n.c = round(5136*0.25,1)) #estimate: 25% of sample (see working paper p. 11)

badrinathan.result6 <- stand.result(eff.type = "reg.coef",
                                    u.s.d = 0.411,  #inverted for consistency   
                                    ctrl.sd = 1.264,  #overall sd of outcome
                                    n.t = round(5109*0.75,1), #estimate: 75% of sample (see working paper p. 11)
                                    n.c = round(5109*0.25,1)) #estimate: 25% of sample (see working paper p. 11)

badrinathan.result7 <- stand.result(eff.type = "reg.coef",
                                    u.s.d = 0.109,  #inverted for consistency   
                                    ctrl.sd = 1.049,  #overall sd of outcome
                                    n.t = round(5117*0.75,1), #estimate: 75% of sample (see working paper p. 11)
                                    n.c = round(5117*0.25,1)) #estimate: 25% of sample (see working paper p. 11)

##########################################################################
#### ATE meta-analysis ####

#(a) RE meta-analysis ####

correction_data <- as.data.frame(cbind(c(huang.result1$results[1],huang.result2$results[1],huang.result3$results[1],huang.result4$results[1],
                                         berinsky.result1$results[1],berinsky.result2$results[1],berinsky.result3$results[1],berinsky.result4$results[1],
                                         nyhanreifler.result1$results[1],nyhanreifler.result2$results[1],nyhanreifler.result3$results[1],nyhanreifler.result4$results[1],
                                         nyhanetal.result1$results[1],nyhanetal.result2$results[1],nyhanetal.result3$results[1],
                                         clayton.result1$results[1], clayton.result2$results[1], clayton.result3$results[1],
                                         woodporter.result01$results[1],woodporter.result02$results[1],woodporter.result04$results[1],woodporter.result05$results[1],
                                         woodporter.result06$results[1],woodporter.result07$results[1],woodporter.result08$results[1],woodporter.result09$results[1],
                                         woodporter.result10$results[1],woodporter.result11$results[1],woodporter.result12$results[1],woodporter.result13$results[1],
                                         woodporter.result14$results[1],woodporter.result15$results[1],woodporter.result16$results[1],woodporter.result17$results[1],
                                         woodporter.result18$results[1],woodporter.result19$results[1],woodporter.result20$results[1],woodporter.result21$results[1],
                                         woodporter.result22$results[1],woodporter.result23$results[1],woodporter.result24$results[1],woodporter.result25$results[1],
                                         badrinathan.result1$results[1],badrinathan.result2$results[1],badrinathan.result3$results[1],badrinathan.result4$results[1],
                                         badrinathan.result5$results[1],badrinathan.result6$results[1],badrinathan.result7$results[1]),
                                       
                                       c(huang.result1$results[3],huang.result2$results[3],huang.result3$results[3],huang.result4$results[3],
                                         berinsky.result1$results[3],berinsky.result2$results[3],berinsky.result3$results[3],berinsky.result4$results[3],
                                         nyhanreifler.result1$results[3],nyhanreifler.result2$results[3],nyhanreifler.result3$results[3],nyhanreifler.result4$results[3],
                                         nyhanetal.result1$results[3],nyhanetal.result2$results[3],nyhanetal.result3$results[3],
                                         clayton.result1$results[3], clayton.result2$results[3], clayton.result3$results[3],
                                         woodporter.result01$results[3],woodporter.result02$results[3],woodporter.result04$results[3],woodporter.result05$results[3],
                                         woodporter.result06$results[3],woodporter.result07$results[3],woodporter.result08$results[3],woodporter.result09$results[3],
                                         woodporter.result10$results[3],woodporter.result11$results[3],woodporter.result12$results[3],woodporter.result13$results[3],
                                         woodporter.result14$results[3],woodporter.result15$results[3],woodporter.result16$results[3],woodporter.result17$results[3],
                                         woodporter.result18$results[3],woodporter.result19$results[3],woodporter.result20$results[3],woodporter.result21$results[3],
                                         woodporter.result22$results[3],woodporter.result23$results[3],woodporter.result24$results[3],woodporter.result25$results[3],
                                         badrinathan.result1$results[3],badrinathan.result2$results[3],badrinathan.result3$results[3],badrinathan.result4$results[3],
                                         badrinathan.result5$results[3],badrinathan.result6$results[3],badrinathan.result7$results[3]),
                                       
                                       c("Huang 2017 (China)","Huang 2017 (China)","Huang 2017 (China)","Huang 2017 (China)","Berinsky 2017 (US)","Berinsky 2017 (US)","Berinsky 2017 (US)","Berinsky 2017 (US)",
                                         "Nyhan and Reifler 2010 (US)","Nyhan and Reifler 2010 (US)", "Nyhan and Reifler 2010 (US)","Nyhan and Reifler 2010 (US)",
                                         "Nyhan et al. 2019 (US)","Nyhan et al. 2019 (US)", "Nyhan et al. 2019 (US)",
                                         "Clayton et al. 2019 (US)", "Clayton et al. 2019 (US)", "Clayton et al. 2019 (US)",
                                         "Wood and Porter 2019 (US)    ", "Wood and Porter 2019 (US)    ", "Wood and Porter 2019 (US)    ", "Wood and Porter 2019 (US)    ",
                                         "Wood and Porter 2019 (US)    ", "Wood and Porter 2019 (US)    ", "Wood and Porter 2019 (US)    ", "Wood and Porter 2019 (US)    ", "Wood and Porter 2019 (US)    ", "Wood and Porter 2019 (US)    ",
                                         "Wood and Porter 2019 (US)    ", "Wood and Porter 2019 (US)    ", "Wood and Porter 2019 (US)    ", "Wood and Porter 2019 (US)    ", "Wood and Porter 2019 (US)    ", "Wood and Porter 2019 (US)    ", 
                                         "Wood and Porter 2019 (US)    ", "Wood and Porter 2019 (US)    ", "Wood and Porter 2019 (US)    ", "Wood and Porter 2019 (US)    ",
                                         "Wood and Porter 2019 (US)    ", "Wood and Porter 2019 (US)    ", "Wood and Porter 2019 (US)    ", "Wood and Porter 2019 (US)    ",
                                         "Badrinathan et al. (India)",  "Badrinathan et al. (India)",  "Badrinathan et al. (India)",   "Badrinathan et al. (India)", 
                                         "Badrinathan et al. (India)",   "Badrinathan et al. (India)", "Badrinathan et al. (India)")  ))

colnames(correction_data) <- c("d","se_d","study")

correction_data$study <- as.character(correction_data$study)
correction_data$d <- as.numeric(as.character(correction_data$d))
correction_data$se_d <- as.numeric(as.character(correction_data$se_d))

#random effects, without unpublished work
meta.re <- rma.mv(d,(se_d)^2, 
                random = list(~ 1 | as.numeric(as.factor(study))), 
                tdist = TRUE, 
                slab = study,
                data = subset(correction_data,correction_data$study != "Badrinathan et al. (India)"))

meta.re$slab <- subset(correction_data$study, correction_data$study != "Badrinathan et al. (India)")

#random effects, with unpublished work
meta.re_withunpub <- rma.mv(d,(se_d)^2, 
                  random = list(~ 1 | as.numeric(as.factor(study))), 
                  tdist = TRUE, 
                  slab = study,
                  data = correction_data)

meta.re_withunpub$slab <- correction_data$study


#fixed effects
meta.fe <- rma(d, 
               (se_d)^2, 
                method = "FE", 
                slab = study,
                data = correction_data)

meta.fe$slab <- correction_data$study

#only elections 

correction_election_data <- as.data.frame(cbind(c(nyhanetal.result1$results[1],nyhanetal.result2$results[1],nyhanetal.result3$results[1]),
                                                c(nyhanetal.result1$results[3],nyhanetal.result2$results[3],nyhanetal.result3$results[3]),
                                                c("Nyhan et al. 2019 (US)","Nyhan et al. 2019 (US)", "Nyhan et al. 2019 (US)") ))

colnames(correction_election_data) <- c("d","se_d","study")

correction_election_data$study <- as.character(correction_election_data$study)
correction_election_data$d <- as.numeric(as.character(correction_election_data$d))
correction_election_data$se_d <- as.numeric(as.character(correction_election_data$se_d))

# meta.re_elections <- rma.mv(d, 
#                      (se_d)^2, 
#                      random = list(~ 1 | as.numeric(as.factor(study))), 
#                      tdist = TRUE, 
#                      slab = study,
#                      data = correction_election_data)

#Removing random list(~ 1 | as.numeric(as.factor(study))) since there is only one study, results are the same
meta.re_elections <- rma.mv(d,
                     (se_d)^2,
                     tdist = TRUE,
                     slab = study,
                     data = correction_election_data)

meta.re_elections$slab <- correction_election_data$study

#(b) forest plots####

#use RE based on results of Q-test
#Figure A2

setEPS()
postscript("Figures/figA2.eps", 
   width = 10, height = 14)
forest(meta.re,
       showweights = TRUE,
       cex=0.8,
       rightlabs = c("95% CI","weight"),
       leftlabs = c("Author"),
       text.predict = "95% PI",
       col.predict = "black",
       weight.study = "random",
       colgap.forest.left = unit(5,"mm"))
dev.off()


#Figure K4

setEPS()
postscript("Figures/figA5.eps", 
   width = 10, height = 14)
forest(meta.re_withunpub,
       showweights = TRUE,
       cex=0.8,
       rightlabs = c("95% CI","weight"),
       leftlabs = c("Author"),
       text.predict = "95% PI",
       col.predict = "black",
       weight.study = "random",
       colgap.forest.left = unit(5,"mm"))
dev.off()

#Figure A4

setEPS()
postscript("Figures/figA4.eps", 
    width = 8, height = 6)
forest(meta.re_elections,
       showweights = TRUE,
       cex=0.8,
       rightlabs = c("95% CI","weight"),
       leftlabs = c("Author"),
       text.predict = "95% PI",
       col.predict = "black",
       colgap.forest.left = unit(5,"mm"))
dev.off()

#(c) p curve####

#Figure A3

setEPS()
postscript("Figures/figA3.eps", 
    width = 8, height = 8)
pcurve.data <- as.data.frame(cbind(correction_data$d,correction_data$se_d,correction_data$study))
pcurve.data$V1 <- as.numeric(pcurve.data$V1)
pcurve.data$V2 <- as.numeric(pcurve.data$V2)
colnames(pcurve.data) <- c("TE","seTE","studlab")
pcurve.data <- subset(pcurve.data,pcurve.data$studlab != "Badrinathan et al. (India)")
pcurve(pcurve.data,dmin=0,dmax=1)
dev.off()

#Sample size cited in paper
#Using sample sizes as sum of n.t. and n.c. from each coefficient's standardized effect size function
results_ss <- c(nrow(subset(dat.berinsky,dat.berinsky$treat==3)) + nrow(subset(dat.berinsky,dat.berinsky$treat==2)),
     nrow(subset(dat.berinsky,dat.berinsky$treat==4)) + nrow(subset(dat.berinsky,dat.berinsky$treat==2)),
     nrow(subset(dat.berinsky,dat.berinsky$treat==5)) + nrow(subset(dat.berinsky,dat.berinsky$treat==2)),
     nrow(subset(dat.berinskycces,dat.berinskycces$randtreat=="c")) + nrow(subset(dat.berinskycces,dat.berinskycces$randtreat=="a")),
     2530+2789,
     1645+2789,
     1707+2989,
     nrow(subset(dat.huang1,dat.huang1$rebuta==1)) + nrow(subset(dat.huang1,dat.huang1$rumor==1)),
     nrow(subset(dat.huang1,dat.huang1$rebutb==1)) + nrow(subset(dat.huang1,dat.huang1$rumor==1)),
     nrow(subset(dat.huang2,dat.huang2$rebuta==1)) + nrow(subset(dat.huang2,dat.huang2$rumor==1)),
     nrow(subset(dat.huang2,dat.huang2$rebutb==1)) + nrow(subset(dat.huang2,dat.huang2$rumor==1)),
     nrow(subset(dat.nyhan1,dat.nyhan1$correction==1 & dat.nyhan1$turk==0)) + nrow(subset(dat.nyhan1,dat.nyhan1$correction==0 & dat.nyhan1$turk==0)),
     nrow(subset(dat.nyhan1,dat.nyhan1$correction==1 & dat.nyhan1$turk==1)) + nrow(subset(dat.nyhan1,dat.nyhan1$correction==0 & dat.nyhan1$turk==1)),
     nrow(subset(dat.nyhan2,ifelse(dat.nyhan2$corr_cond == "Correction",1,0) == 1)) + nrow(subset(dat.nyhan2,ifelse(dat.nyhan2$corr_cond == "Correction",1,0) == 0)),
     nrow(subset(dat.nyhanreifler1,dat.nyhanreifler1$iraqcorr==1)) + nrow(subset(dat.nyhanreifler1,dat.nyhanreifler1$iraqcorr==0)),
     nrow(subset(dat.nyhanreifler2,dat.nyhanreifler2$iraqcorr==1)) + nrow(subset(dat.nyhanreifler2,dat.nyhanreifler2$iraqcorr==0)),
     nrow(subset(dat.nyhanreifler2,dat.nyhanreifler2$taxcutcorr==1)) + nrow(subset(dat.nyhanreifler2,dat.nyhanreifler2$taxcutcorr==0)),
     nrow(subset(dat.nyhanreifler2,dat.nyhanreifler2$sccorr==1)) + nrow(subset(dat.nyhanreifler2,dat.nyhanreifler2$sccorr==0)),
     nrow(subset(dat.woodporter1,dat.woodporter1$corr=="Correction" & dat.woodporter1$item == "Gun violence at all time high (Clinton)(1)")) +
       nrow(subset(dat.woodporter1,dat.woodporter1$corr=="No Correction" & dat.woodporter1$item == "Gun violence at all time high (Clinton)(1)")),
     nrow(subset(dat.woodporter1,dat.woodporter1$corr=="Correction" & dat.woodporter1$item == "Most prisoners serving drug sentences (Obama)(1)")) +
       nrow(subset(dat.woodporter1,dat.woodporter1$corr=="No Correction" & dat.woodporter1$item == "Most prisoners serving drug sentences (Obama)(1)")),
     nrow(subset(dat.woodporter1,dat.woodporter1$corr=="Correction" & dat.woodporter1$item == "Workers pay more tax than financiers (Clinton)(1)")) +
       nrow(subset(dat.woodporter1,dat.woodporter1$corr=="No Correction" & dat.woodporter1$item == "Workers pay more tax than financiers (Clinton)(1)")),
     nrow(subset(dat.woodporter1,dat.woodporter1$corr=="Correction" & dat.woodporter1$item == "Discrimin. sole cause wage gap (Obama)(1)")) +
       nrow(subset(dat.woodporter1,dat.woodporter1$corr=="No Correction" & dat.woodporter1$item == "Discrimin. sole cause wage gap (Obama)(1)")),
     nrow(subset(dat.woodporter1,dat.woodporter1$corr=="Correction" & dat.woodporter1$item == "Obama cuts defense spending (Rubio)(1)")) +
       nrow(subset(dat.woodporter1,dat.woodporter1$corr=="No Correction" & dat.woodporter1$item == "Obama cuts defense spending (Rubio)(1)")),
     nrow(subset(dat.woodporter1,dat.woodporter1$corr=="Correction" & dat.woodporter1$item == "Undocumented disprop. criminal (Trump)(1)")) +
       nrow(subset(dat.woodporter1,dat.woodporter1$corr=="No Correction" & dat.woodporter1$item == "Undocumented disprop. criminal (Trump)(1)")),
     nrow(subset(dat.woodporter1,dat.woodporter1$corr=="Correction" & dat.woodporter1$item == "Surge in killings of police officers (Cruz)(1)")) +
       nrow(subset(dat.woodporter1,dat.woodporter1$corr=="No Correction" & dat.woodporter1$item == "Surge in killings of police officers (Cruz)(1)")),
     nrow(subset(dat.woodporter1,dat.woodporter1$corr=="Correction" & dat.woodporter1$item == "US taxes highest in world (Trump)(1)")) +
       nrow(subset(dat.woodporter1,dat.woodporter1$corr=="No Correction" & dat.woodporter1$item == "US taxes highest in world (Trump)(1)")),
     nrow(subset(dat.woodporter1,dat.woodporter1$corr=="Correction" & dat.woodporter1$item == "Obama passed TARP (Palin)(2)")) +
       nrow(subset(dat.woodporter1,dat.woodporter1$corr=="No Correction" & dat.woodporter1$item == "Obama passed TARP (Palin)(2)")),
     nrow(subset(dat.woodporter1,dat.woodporter1$corr=="Correction" & dat.woodporter1$item == "Obama passed TARP (Obama)(2)")) +
       nrow(subset(dat.woodporter1,dat.woodporter1$corr=="No Correction" & dat.woodporter1$item == "Obama passed TARP (Obama)(2)")),
     nrow(subset(dat.woodporter1,dat.woodporter1$corr=="Correction" & dat.woodporter1$item == "Obama accomodates undocumented (Cruz)(2)")) +
       nrow(subset(dat.woodporter1,dat.woodporter1$corr=="No Correction" & dat.woodporter1$item == "Obama accomodates undocumented (Cruz)(2)")),
     nrow(subset(dat.woodporter1,dat.woodporter1$corr=="Correction" & dat.woodporter1$item == "Obama accomodates undocumented (Gutiérrez)(2)")) + 
       nrow(subset(dat.woodporter1,dat.woodporter1$corr=="No Correction" & dat.woodporter1$item == "Obama accomodates undocumented (Gutiérrez)(2)")),
     nrow(subset(dat.woodporter1,dat.woodporter1$corr=="Correction" & dat.woodporter1$item == "Spiraling teen pregnancy rate (Carson)(2)")) +
       nrow(subset(dat.woodporter1,dat.woodporter1$corr=="No Correction" & dat.woodporter1$item == "Spiraling teen pregnancy rate (Carson)(2)")),
     nrow(subset(dat.woodporter1,dat.woodporter1$corr=="Correction" & dat.woodporter1$item == "Spiraling teen pregnancy rate (Lee)(2)")) +
       nrow(subset(dat.woodporter1,dat.woodporter1$corr=="No Correction" & dat.woodporter1$item == "Spiraling teen pregnancy rate (Lee)(2)")),
     nrow(subset(dat.woodporter1,dat.woodporter1$corr=="Correction" & dat.woodporter1$item == "China holds majority of US debt (Romney)(2)")) +
       nrow(subset(dat.woodporter1,dat.woodporter1$corr=="No Correction" & dat.woodporter1$item == "China holds majority of US debt (Romney)(2)")),
     nrow(subset(dat.woodporter1,dat.woodporter1$corr=="Correction" & dat.woodporter1$item == "China holds majority of US debt (Obama)(2)")) +
       nrow(subset(dat.woodporter1,dat.woodporter1$corr=="No Correction" & dat.woodporter1$item == "China holds majority of US debt (Obama)(2)")),
     nrow(subset(dat.woodporter1,dat.woodporter1$corr=="Correction" & dat.woodporter1$item == "Whites imminently a minority (Graham)(2)")) +
       nrow(subset(dat.woodporter1,dat.woodporter1$corr=="No Correction" & dat.woodporter1$item == "Whites imminently a minority (Graham)(2)")),
     nrow(subset(dat.woodporter1,dat.woodporter1$corr=="Correction" & dat.woodporter1$item == "Whites imminently a minority (Longoria)(2)")) +
       nrow(subset(dat.woodporter1,dat.woodporter1$corr=="No Correction" & dat.woodporter1$item == "Whites imminently a minority (Longoria)(2)")),
     nrow(subset(dat.woodporter1,dat.woodporter1$corr=="Correction" & dat.woodporter1$item == "Spiraling Chicago gun violence (LaPierre)(2)")) +
       nrow(subset(dat.woodporter1,dat.woodporter1$corr=="No Correction" & dat.woodporter1$item == "Spiraling Chicago gun violence (LaPierre)(2)")),
     nrow(subset(dat.woodporter1,dat.woodporter1$corr=="Correction" & dat.woodporter1$item == "Spiraling Chicago gun violence (Obama)(2)")) +
       nrow(subset(dat.woodporter1,dat.woodporter1$corr=="No Correction" & dat.woodporter1$item == "Spiraling Chicago gun violence (Obama)(2)")),
     nrow(subset(dat.woodporter1,dat.woodporter1$corr=="Correction" & dat.woodporter1$item == "Spiraling abortion rate (Ryan)(2)")) +
       nrow(subset(dat.woodporter1,dat.woodporter1$corr=="No Correction" & dat.woodporter1$item == "Spiraling abortion rate (Ryan)(2)")),
     nrow(subset(dat.woodporter1,dat.woodporter1$corr=="Correction" & dat.woodporter1$item == "Spiraling abortion rate (Obama)(2)")) +
       nrow(subset(dat.woodporter1,dat.woodporter1$corr=="No Correction" & dat.woodporter1$item == "Spiraling abortion rate (Obama)(2)")),
     nrow(subset(dat.woodporter1,dat.woodporter1$corr=="Correction" & dat.woodporter1$item == "Obama restricts drones' use (Graham)(2)"))+
       nrow(subset(dat.woodporter1,dat.woodporter1$corr=="No Correction" & dat.woodporter1$item == "Obama restricts drones' use (Graham)(2)")),
     nrow(subset(dat.woodporter1,dat.woodporter1$corr=="Correction" & dat.woodporter1$item == "Obama restricts drones' use (Obama)(2)")) +
       nrow(subset(dat.woodporter1,dat.woodporter1$corr=="No Correction" & dat.woodporter1$item == "Obama restricts drones' use (Obama)(2)")) )

mean(results_ss)
#Average size of samples used in the meta-analysis

#(d) comparing estimates####

### Figure A6

#Getting Batista Pereira et al estimate
#format to obtain results in stata: reg disbelief1 i.fact2 i.newstype, robust 
#results are similar without fixed effects (0.0350572, std. error 0.0216826)
batista.result2 <- stand.result(eff.type = "reg.coef",
                              u.s.d = 0.031255,  #UOL fact checking compared to baseline (inverted for consistency)
                              ctrl.sd = 0.4809727,  #control
                              n.t = 1142,
                              n.c = 1094)

simple.ate <- as.data.frame(matrix(NA,2,4))
colnames(simple.ate) <- c("Study","lower","est","upper")
simple.ate[1,] <- c("Batista Pereira et al. 2020 (Brazil)",0.065 - 1.96*0.045,0.065,0.065 + 1.96*0.045) 
simple.ate[2,] <- c("Meta-Analysis", meta.re$b[,1] - 1.96*meta.re$se , meta.re$b[,1], meta.re$b[,1] + 1.96*meta.re$se)
simple.ate <- simple.ate %>% mutate(lower = as.numeric(lower), est = as.numeric(est), 
                                    upper = as.numeric(upper))


#New Function to compare estimates
#Compare the estimates from meta and ours
#testing statistical difference between estimates
difftest2 <- function(est1, est2, s1, s2, alpha = 0.05) {
  dom <- est1-est2
  se <- sqrt((s1^2) + (s2^2))
  ci <- se*qnorm(1-(alpha/2))
  pval <- 2*pnorm(abs(dom/se), lower.tail = FALSE)
  result <- c(est1, est2, dom, se, dom-ci, dom+ci, pval)
  names(result) <- c("est.1", "est.2", "dom", "se", "l.ci", 
                     "u.ci", "pval")
  return(result)
}

difftest2(0.065,meta.re$b[,1],0.045,meta.re$se) #p = 0.009

setEPS()
postscript("Figures/figA6.eps", 
           width = 8, height = 8)
ggplot(data = simple.ate, aes(y=est, ymin=lower, x=Study, ymax=upper)) +
  geom_linerange(aes(colour=Study),size=1.75) +
  geom_point(aes(colour=Study),size=2.5) +
  geom_hline(yintercept =0, size=1, linetype = "dotted") +
  ylim(-1,1) + 
  ylab("Estimated ATE") +
  xlab(element_blank())+
  theme(panel.background = element_blank(), 
        text = element_text(size=16),
        legend.position = "none",
        plot.title = element_text(hjust = 0.5, face="bold"),
        panel.grid.major = element_blank(), 
        panel.grid.minor = element_blank(),
        axis.ticks.x=element_blank(),
        axis.text.x=element_text(face="bold"),
        axis.title.y=element_text(angle=90, vjust=0.5),
        axis.text.y=element_text(face="bold"),
        panel.border = element_rect(colour = "black", fill=NA, size=1.5)) +
  scale_color_manual(values=c("black","black"))
dev.off()


#6 appendix: original authors' code, using interactions####

#nyhan et al. 2019####
#study 1 (see table 1)

nyhanetal.result1alt <- stand.result(eff.type = "reg.coef",
                                     u.s.d = summary(lm(outcome ~ trumpsupport*trumpcrime + correction*trumpsupport + questionstats*trumpsupport + fbict*trumpsupport, 
                                                        dat=subset(dat.nyhan1, turk==0 & (clintonsupport==1 | trumpsupport == 1))))$coefficients[4], #fact check
                                     ctrl.sd = sd(dat.nyhan1$outcome[dat.nyhan1$correction==0 & dat.nyhan1$turk==0],na.rm=T),  #no fact check
                                     n.t = nrow(subset(dat.nyhan1,dat.nyhan1$correction==1 & dat.nyhan1$turk==0)),
                                     n.c = nrow(subset(dat.nyhan1,dat.nyhan1$correction==0 & dat.nyhan1$turk==0)) )

nyhanetal.result2alt <- stand.result(eff.type = "reg.coef",
                                     u.s.d = summary(lm(outcome ~ trumpsupport*trumpcrime + correction*trumpsupport + questionstats*trumpsupport + fbict*trumpsupport, 
                                                        dat=subset(dat.nyhan1, turk==1 & (clintonsupport==1 | trumpsupport == 1))))$coefficients[4], #fact check
                                     ctrl.sd = sd(dat.nyhan1$outcome[dat.nyhan1$correction==0 & dat.nyhan1$turk==1],na.rm=T),  #no fact check
                                     n.t = nrow(subset(dat.nyhan1,dat.nyhan1$correction==1 & dat.nyhan1$turk==1)),
                                     n.c = nrow(subset(dat.nyhan1,dat.nyhan1$correction==0 & dat.nyhan1$turk==1)) )

#study 2 


nyhanetal.result3alt <- stand.result(eff.type = "reg.coef",
                                     u.s.d = summary(lm(outcome ~ ifelse(corr_cond == "Correction",1,0)*ifelse(trumpvoter == "1. Non Trump Voter",1,0), 
                                                        dat=subset(dat.nyhan2)))$coefficients[2], #fact check
                                     ctrl.sd = sd(dat.nyhan2$outcome[ifelse(dat.nyhan2$corr_cond == "Correction",1,0) == 0],na.rm=T),  #no fact check
                                     n.t = nrow(subset(dat.nyhan2,ifelse(dat.nyhan2$corr_cond == "Correction",1,0) == 1)),
                                     n.c = nrow(subset(dat.nyhan2,ifelse(dat.nyhan2$corr_cond == "Correction",1,0) == 0)) )

#wood and porter 2019####

#STUDY 1
#(note results are numbered in accordance with their order of appearance in Table 1)

woodporter.result01alt <- stand.result(eff.type = "reg.coef",
                                       u.s.d = summary(lm(outcome ~ ifelse(corr=="Correction",1,0)*ideol, 
                                                          dat=subset(dat.woodporter1,dat.woodporter1$item == "Gun violence at all time high (Clinton)(1)")))$coefficients[2], #item 1 correction
                                       ctrl.sd = sd(dat.woodporter1$outcome[dat.woodporter1$corr=="No Correction" & dat.woodporter1$item == "Gun violence at all time high (Clinton)(1)"],na.rm=T),  #no correction
                                       n.t = nrow(subset(dat.woodporter1,dat.woodporter1$corr=="Correction" & dat.woodporter1$item == "Gun violence at all time high (Clinton)(1)")),
                                       n.c = nrow(subset(dat.woodporter1,dat.woodporter1$corr=="No Correction" & dat.woodporter1$item == "Gun violence at all time high (Clinton)(1)")) 
)

woodporter.result02alt <- stand.result(eff.type = "reg.coef",
                                       u.s.d = summary(lm(outcome ~ ifelse(corr=="Correction",1,0)*ideol, 
                                                          dat=subset(dat.woodporter1,dat.woodporter1$item == "Most prisoners serving drug sentences (Obama)(1)")))$coefficients[2], #item 2 correction
                                       ctrl.sd = sd(dat.woodporter1$outcome[dat.woodporter1$corr=="No Correction" & dat.woodporter1$item == "Most prisoners serving drug sentences (Obama)(1)"],na.rm=T),  #no correction
                                       n.t = nrow(subset(dat.woodporter1,dat.woodporter1$corr=="Correction" & dat.woodporter1$item == "Most prisoners serving drug sentences (Obama)(1)")),
                                       n.c = nrow(subset(dat.woodporter1,dat.woodporter1$corr=="No Correction" & dat.woodporter1$item == "Most prisoners serving drug sentences (Obama)(1)")) 
)

#woodporter.result03alt <- NA   #more jobs in solar than oil (Clinton) does not exist for study 1 despite indication in Table 1 

woodporter.result04alt <- stand.result(eff.type = "reg.coef",
                                       u.s.d = summary(lm(outcome ~ ifelse(corr=="Correction",1,0)*ideol, 
                                                          dat=subset(dat.woodporter1,dat.woodporter1$item == "Workers pay more tax than financiers (Clinton)(1)")))$coefficients[2], #item 4 correction
                                       ctrl.sd = sd(dat.woodporter1$outcome[dat.woodporter1$corr=="No Correction" & dat.woodporter1$item == "Workers pay more tax than financiers (Clinton)(1)"],na.rm=T),  #no correction
                                       n.t = nrow(subset(dat.woodporter1,dat.woodporter1$corr=="Correction" & dat.woodporter1$item == "Workers pay more tax than financiers (Clinton)(1)")),
                                       n.c = nrow(subset(dat.woodporter1,dat.woodporter1$corr=="No Correction" & dat.woodporter1$item == "Workers pay more tax than financiers (Clinton)(1)")) 
)


woodporter.result05alt <- stand.result(eff.type = "reg.coef",
                                       u.s.d = summary(lm(outcome ~ ifelse(corr=="Correction",1,0)*ideol, 
                                                          dat=subset(dat.woodporter1,dat.woodporter1$item == "Discrimin. sole cause wage gap (Obama)(1)")))$coefficients[2], #item 5 correction
                                       ctrl.sd = sd(dat.woodporter1$outcome[dat.woodporter1$corr=="No Correction" & dat.woodporter1$item == "Discrimin. sole cause wage gap (Obama)(1)"],na.rm=T),  #no correction
                                       n.t = nrow(subset(dat.woodporter1,dat.woodporter1$corr=="Correction" & dat.woodporter1$item == "Discrimin. sole cause wage gap (Obama)(1)")),
                                       n.c = nrow(subset(dat.woodporter1,dat.woodporter1$corr=="No Correction" & dat.woodporter1$item == "Discrimin. sole cause wage gap (Obama)(1)")) 
)


woodporter.result06alt <- stand.result(eff.type = "reg.coef",
                                       u.s.d = summary(lm(outcome ~ ifelse(corr=="Correction",1,0)*ideol, 
                                                          dat=subset(dat.woodporter1,dat.woodporter1$item == "Obama cuts defense spending (Rubio)(1)")))$coefficients[2], #item 6 correction
                                       ctrl.sd = sd(dat.woodporter1$outcome[dat.woodporter1$corr=="No Correction" & dat.woodporter1$item == "Obama cuts defense spending (Rubio)(1)"],na.rm=T),  #no correction
                                       n.t = nrow(subset(dat.woodporter1,dat.woodporter1$corr=="Correction" & dat.woodporter1$item == "Obama cuts defense spending (Rubio)(1)")),
                                       n.c = nrow(subset(dat.woodporter1,dat.woodporter1$corr=="No Correction" & dat.woodporter1$item == "Obama cuts defense spending (Rubio)(1)")) 
)


woodporter.result07alt <- stand.result(eff.type = "reg.coef",
                                       u.s.d = summary(lm(outcome ~ ifelse(corr=="Correction",1,0)*ideol, 
                                                          dat=subset(dat.woodporter1,dat.woodporter1$item == "Undocumented disprop. criminal (Trump)(1)")))$coefficients[2], #item 7 correction
                                       ctrl.sd = sd(dat.woodporter1$outcome[dat.woodporter1$corr=="No Correction" & dat.woodporter1$item == "Undocumented disprop. criminal (Trump)(1)"],na.rm=T),  #no correction
                                       n.t = nrow(subset(dat.woodporter1,dat.woodporter1$corr=="Correction" & dat.woodporter1$item == "Undocumented disprop. criminal (Trump)(1)")),
                                       n.c = nrow(subset(dat.woodporter1,dat.woodporter1$corr=="No Correction" & dat.woodporter1$item == "Undocumented disprop. criminal (Trump)(1)")) 
)


woodporter.result08alt <- stand.result(eff.type = "reg.coef",
                                       u.s.d = summary(lm(outcome ~ ifelse(corr=="Correction",1,0)*ideol, 
                                                          dat=subset(dat.woodporter1,dat.woodporter1$item == "Surge in killings of police officers (Cruz)(1)")))$coefficients[2], #item 8 correction
                                       ctrl.sd = sd(dat.woodporter1$outcome[dat.woodporter1$corr=="No Correction" & dat.woodporter1$item == "Surge in killings of police officers (Cruz)(1)"],na.rm=T),  #no correction
                                       n.t = nrow(subset(dat.woodporter1,dat.woodporter1$corr=="Correction" & dat.woodporter1$item == "Surge in killings of police officers (Cruz)(1)")),
                                       n.c = nrow(subset(dat.woodporter1,dat.woodporter1$corr=="No Correction" & dat.woodporter1$item == "Surge in killings of police officers (Cruz)(1)")) 
)


woodporter.result09alt <- stand.result(eff.type = "reg.coef",
                                       u.s.d = summary(lm(outcome ~ ifelse(corr=="Correction",1,0)*ideol, 
                                                          dat=subset(dat.woodporter1,dat.woodporter1$item == "US taxes highest in world (Trump)(1)")))$coefficients[2], #item 9 correction
                                       ctrl.sd = sd(dat.woodporter1$outcome[dat.woodporter1$corr=="No Correction" & dat.woodporter1$item == "US taxes highest in world (Trump)(1)"],na.rm=T),  #no correction
                                       n.t = nrow(subset(dat.woodporter1,dat.woodporter1$corr=="Correction" & dat.woodporter1$item == "US taxes highest in world (Trump)(1)")),
                                       n.c = nrow(subset(dat.woodporter1,dat.woodporter1$corr=="No Correction" & dat.woodporter1$item == "US taxes highest in world (Trump)(1)")) 
)



#STUDY 2

woodporter.result10alt <- stand.result(eff.type = "reg.coef",
                                       u.s.d = summary(lm(outcome ~ ifelse(corr=="Correction",1,0)*ideol, 
                                                          dat=subset(dat.woodporter1,dat.woodporter1$item == "Obama passed TARP (Palin)(2)")))$coefficients[2], #item 10 correction
                                       ctrl.sd = sd(dat.woodporter1$outcome[dat.woodporter1$corr=="No Correction" & dat.woodporter1$item == "Obama passed TARP (Palin)(2)"],na.rm=T),  #no correction
                                       n.t = nrow(subset(dat.woodporter1,dat.woodporter1$corr=="Correction" & dat.woodporter1$item == "Obama passed TARP (Palin)(2)")),
                                       n.c = nrow(subset(dat.woodporter1,dat.woodporter1$corr=="No Correction" & dat.woodporter1$item == "Obama passed TARP (Palin)(2)")) 
)

woodporter.result11alt <- stand.result(eff.type = "reg.coef",
                                       u.s.d = summary(lm(outcome ~ ifelse(corr=="Correction",1,0)*ideol, 
                                                          dat=subset(dat.woodporter1,dat.woodporter1$item == "Obama passed TARP (Obama)(2)")))$coefficients[2], #item 11 correction
                                       ctrl.sd = sd(dat.woodporter1$outcome[dat.woodporter1$corr=="No Correction" & dat.woodporter1$item == "Obama passed TARP (Obama)(2)"],na.rm=T),  #no correction
                                       n.t = nrow(subset(dat.woodporter1,dat.woodporter1$corr=="Correction" & dat.woodporter1$item == "Obama passed TARP (Obama)(2)")),
                                       n.c = nrow(subset(dat.woodporter1,dat.woodporter1$corr=="No Correction" & dat.woodporter1$item == "Obama passed TARP (Obama)(2)")) 
)

woodporter.result12alt <- stand.result(eff.type = "reg.coef",
                                       u.s.d = summary(lm(outcome ~ ifelse(corr=="Correction",1,0)*ideol, 
                                                          dat=subset(dat.woodporter1,dat.woodporter1$item == "Obama accomodates undocumented (Cruz)(2)")))$coefficients[2], #item 12 correction
                                       ctrl.sd = sd(dat.woodporter1$outcome[dat.woodporter1$corr=="No Correction" & dat.woodporter1$item == "Obama accomodates undocumented (Cruz)(2)"],na.rm=T),  #no correction
                                       n.t = nrow(subset(dat.woodporter1,dat.woodporter1$corr=="Correction" & dat.woodporter1$item == "Obama accomodates undocumented (Cruz)(2)")),
                                       n.c = nrow(subset(dat.woodporter1,dat.woodporter1$corr=="No Correction" & dat.woodporter1$item == "Obama accomodates undocumented (Cruz)(2)")) 
)

woodporter.result13alt <- stand.result(eff.type = "reg.coef",
                                       u.s.d = summary(lm(outcome ~ ifelse(corr=="Correction",1,0)*ideol, 
                                                          dat=subset(dat.woodporter1,dat.woodporter1$item == "Obama accomodates undocumented (Gutiérrez)(2)")))$coefficients[2], #item 13 correction
                                       ctrl.sd = sd(dat.woodporter1$outcome[dat.woodporter1$corr=="No Correction" & dat.woodporter1$item == "Obama accomodates undocumented (Gutiérrez)(2)"],na.rm=T),  #no correction
                                       n.t = nrow(subset(dat.woodporter1,dat.woodporter1$corr=="Correction" & dat.woodporter1$item == "Obama accomodates undocumented (Gutiérrez)(2)")),
                                       n.c = nrow(subset(dat.woodporter1,dat.woodporter1$corr=="No Correction" & dat.woodporter1$item == "Obama accomodates undocumented (Gutiérrez)(2)")) 
)

woodporter.result14alt <- stand.result(eff.type = "reg.coef",
                                       u.s.d = summary(lm(outcome ~ ifelse(corr=="Correction",1,0)*ideol, 
                                                          dat=subset(dat.woodporter1,dat.woodporter1$item == "Spiraling teen pregnancy rate (Carson)(2)")))$coefficients[2], #item 14 correction
                                       ctrl.sd = sd(dat.woodporter1$outcome[dat.woodporter1$corr=="No Correction" & dat.woodporter1$item == "Spiraling teen pregnancy rate (Carson)(2)"],na.rm=T),  #no correction
                                       n.t = nrow(subset(dat.woodporter1,dat.woodporter1$corr=="Correction" & dat.woodporter1$item == "Spiraling teen pregnancy rate (Carson)(2)")),
                                       n.c = nrow(subset(dat.woodporter1,dat.woodporter1$corr=="No Correction" & dat.woodporter1$item == "Spiraling teen pregnancy rate (Carson)(2)")) 
)

woodporter.result15alt <- stand.result(eff.type = "reg.coef",
                                       u.s.d = summary(lm(outcome ~ ifelse(corr=="Correction",1,0)*ideol, 
                                                          dat=subset(dat.woodporter1,dat.woodporter1$item == "Spiraling teen pregnancy rate (Lee)(2)")))$coefficients[2], #item 15 correction
                                       ctrl.sd = sd(dat.woodporter1$outcome[dat.woodporter1$corr=="No Correction" & dat.woodporter1$item == "Spiraling teen pregnancy rate (Lee)(2)"],na.rm=T),  #no correction
                                       n.t = nrow(subset(dat.woodporter1,dat.woodporter1$corr=="Correction" & dat.woodporter1$item == "Spiraling teen pregnancy rate (Lee)(2)")),
                                       n.c = nrow(subset(dat.woodporter1,dat.woodporter1$corr=="No Correction" & dat.woodporter1$item == "Spiraling teen pregnancy rate (Lee)(2)")) 
)

woodporter.result16alt <- stand.result(eff.type = "reg.coef",
                                       u.s.d = summary(lm(outcome ~ ifelse(corr=="Correction",1,0)*ideol, 
                                                          dat=subset(dat.woodporter1,dat.woodporter1$item == "China holds majority of US debt (Romney)(2)")))$coefficients[2], #item 16 correction
                                       ctrl.sd = sd(dat.woodporter1$outcome[dat.woodporter1$corr=="No Correction" & dat.woodporter1$item == "China holds majority of US debt (Romney)(2)"],na.rm=T),  #no correction
                                       n.t = nrow(subset(dat.woodporter1,dat.woodporter1$corr=="Correction" & dat.woodporter1$item == "China holds majority of US debt (Romney)(2)")),
                                       n.c = nrow(subset(dat.woodporter1,dat.woodporter1$corr=="No Correction" & dat.woodporter1$item == "China holds majority of US debt (Romney)(2)")) 
)

woodporter.result17alt <- stand.result(eff.type = "reg.coef",
                                       u.s.d = summary(lm(outcome ~ ifelse(corr=="Correction",1,0)*ideol, 
                                                          dat=subset(dat.woodporter1,dat.woodporter1$item == "China holds majority of US debt (Obama)(2)")))$coefficients[2], #item 17 correction
                                       ctrl.sd = sd(dat.woodporter1$outcome[dat.woodporter1$corr=="No Correction" & dat.woodporter1$item == "China holds majority of US debt (Obama)(2)"],na.rm=T),  #no correction
                                       n.t = nrow(subset(dat.woodporter1,dat.woodporter1$corr=="Correction" & dat.woodporter1$item == "China holds majority of US debt (Obama)(2)")),
                                       n.c = nrow(subset(dat.woodporter1,dat.woodporter1$corr=="No Correction" & dat.woodporter1$item == "China holds majority of US debt (Obama)(2)")) 
)

woodporter.result18alt <- stand.result(eff.type = "reg.coef",
                                       u.s.d = summary(lm(outcome ~ ifelse(corr=="Correction",1,0)*ideol, 
                                                          dat=subset(dat.woodporter1,dat.woodporter1$item == "Whites imminently a minority (Graham)(2)")))$coefficients[2], #item 18 correction
                                       ctrl.sd = sd(dat.woodporter1$outcome[dat.woodporter1$corr=="No Correction" & dat.woodporter1$item == "Whites imminently a minority (Graham)(2)"],na.rm=T),  #no correction
                                       n.t = nrow(subset(dat.woodporter1,dat.woodporter1$corr=="Correction" & dat.woodporter1$item == "Whites imminently a minority (Graham)(2)")),
                                       n.c = nrow(subset(dat.woodporter1,dat.woodporter1$corr=="No Correction" & dat.woodporter1$item == "Whites imminently a minority (Graham)(2)")) 
)

woodporter.result19alt <- stand.result(eff.type = "reg.coef",
                                       u.s.d = summary(lm(outcome ~ ifelse(corr=="Correction",1,0)*ideol, 
                                                          dat=subset(dat.woodporter1,dat.woodporter1$item == "Whites imminently a minority (Longoria)(2)")))$coefficients[2], #item 19 correction
                                       ctrl.sd = sd(dat.woodporter1$outcome[dat.woodporter1$corr=="No Correction" & dat.woodporter1$item == "Whites imminently a minority (Longoria)(2)"],na.rm=T),  #no correction
                                       n.t = nrow(subset(dat.woodporter1,dat.woodporter1$corr=="Correction" & dat.woodporter1$item == "Whites imminently a minority (Longoria)(2)")),
                                       n.c = nrow(subset(dat.woodporter1,dat.woodporter1$corr=="No Correction" & dat.woodporter1$item == "Whites imminently a minority (Longoria)(2)")) 
)

woodporter.result20alt <- stand.result(eff.type = "reg.coef",
                                       u.s.d = summary(lm(outcome ~ ifelse(corr=="Correction",1,0)*ideol, 
                                                          dat=subset(dat.woodporter1,dat.woodporter1$item == "Spiraling Chicago gun violence (LaPierre)(2)")))$coefficients[2], #item 20 correction
                                       ctrl.sd = sd(dat.woodporter1$outcome[dat.woodporter1$corr=="No Correction" & dat.woodporter1$item == "Spiraling Chicago gun violence (LaPierre)(2)"],na.rm=T),  #no correction
                                       n.t = nrow(subset(dat.woodporter1,dat.woodporter1$corr=="Correction" & dat.woodporter1$item == "Spiraling Chicago gun violence (LaPierre)(2)")),
                                       n.c = nrow(subset(dat.woodporter1,dat.woodporter1$corr=="No Correction" & dat.woodporter1$item == "Spiraling Chicago gun violence (LaPierre)(2)")) 
)

woodporter.result21alt <- stand.result(eff.type = "reg.coef",
                                       u.s.d = summary(lm(outcome ~ ifelse(corr=="Correction",1,0)*ideol, 
                                                          dat=subset(dat.woodporter1,dat.woodporter1$item == "Spiraling Chicago gun violence (Obama)(2)")))$coefficients[2], #item 21 correction
                                       ctrl.sd = sd(dat.woodporter1$outcome[dat.woodporter1$corr=="No Correction" & dat.woodporter1$item == "Spiraling Chicago gun violence (Obama)(2)"],na.rm=T),  #no correction
                                       n.t = nrow(subset(dat.woodporter1,dat.woodporter1$corr=="Correction" & dat.woodporter1$item == "Spiraling Chicago gun violence (Obama)(2)")),
                                       n.c = nrow(subset(dat.woodporter1,dat.woodporter1$corr=="No Correction" & dat.woodporter1$item == "Spiraling Chicago gun violence (Obama)(2)")) 
)

woodporter.result22alt <- stand.result(eff.type = "reg.coef",
                                       u.s.d = summary(lm(outcome ~ ifelse(corr=="Correction",1,0)*ideol, 
                                                          dat=subset(dat.woodporter1,dat.woodporter1$item == "Spiraling abortion rate (Ryan)(2)")))$coefficients[2], #item 22 correction
                                       ctrl.sd = sd(dat.woodporter1$outcome[dat.woodporter1$corr=="No Correction" & dat.woodporter1$item == "Spiraling abortion rate (Ryan)(2)"],na.rm=T),  #no correction
                                       n.t = nrow(subset(dat.woodporter1,dat.woodporter1$corr=="Correction" & dat.woodporter1$item == "Spiraling abortion rate (Ryan)(2)")),
                                       n.c = nrow(subset(dat.woodporter1,dat.woodporter1$corr=="No Correction" & dat.woodporter1$item == "Spiraling abortion rate (Ryan)(2)")) 
)

woodporter.result23alt <- stand.result(eff.type = "reg.coef",
                                       u.s.d = summary(lm(outcome ~ ifelse(corr=="Correction",1,0)*ideol, 
                                                          dat=subset(dat.woodporter1,dat.woodporter1$item == "Spiraling abortion rate (Obama)(2)")))$coefficients[2], #item 23 correction
                                       ctrl.sd = sd(dat.woodporter1$outcome[dat.woodporter1$corr=="No Correction" & dat.woodporter1$item == "Spiraling abortion rate (Obama)(2)"],na.rm=T),  #no correction
                                       n.t = nrow(subset(dat.woodporter1,dat.woodporter1$corr=="Correction" & dat.woodporter1$item == "Spiraling abortion rate (Obama)(2)")),
                                       n.c = nrow(subset(dat.woodporter1,dat.woodporter1$corr=="No Correction" & dat.woodporter1$item == "Spiraling abortion rate (Obama)(2)")) 
)

woodporter.result24alt <- stand.result(eff.type = "reg.coef",
                                       u.s.d = summary(lm(outcome ~ ifelse(corr=="Correction",1,0)*ideol, 
                                                          dat=subset(dat.woodporter1,dat.woodporter1$item == "Obama restricts drones' use (Graham)(2)")))$coefficients[2], #item 24 correction
                                       ctrl.sd = sd(dat.woodporter1$outcome[dat.woodporter1$corr=="No Correction" & dat.woodporter1$item == "Obama restricts drones' use (Graham)(2)"],na.rm=T),  #no correction
                                       n.t = nrow(subset(dat.woodporter1,dat.woodporter1$corr=="Correction" & dat.woodporter1$item == "Obama restricts drones' use (Graham)(2)")),
                                       n.c = nrow(subset(dat.woodporter1,dat.woodporter1$corr=="No Correction" & dat.woodporter1$item == "Obama restricts drones' use (Graham)(2)")) 
)

woodporter.result25alt <- stand.result(eff.type = "reg.coef",
                                       u.s.d = summary(lm(outcome ~ ifelse(corr=="Correction",1,0)*ideol, 
                                                          dat=subset(dat.woodporter1,dat.woodporter1$item == "Obama restricts drones' use (Obama)(2)")))$coefficients[2], #item 25 correction
                                       ctrl.sd = sd(dat.woodporter1$outcome[dat.woodporter1$corr=="No Correction" & dat.woodporter1$item == "Obama restricts drones' use (Obama)(2)"],na.rm=T),  #no correction
                                       n.t = nrow(subset(dat.woodporter1,dat.woodporter1$corr=="Correction" & dat.woodporter1$item == "Obama restricts drones' use (Obama)(2)")),
                                       n.c = nrow(subset(dat.woodporter1,dat.woodporter1$corr=="No Correction" & dat.woodporter1$item == "Obama restricts drones' use (Obama)(2)")) 
)

###updated meta-analysis and forest plot####

correction_data_alt <- as.data.frame(cbind(c(huang.result1$results[1],huang.result2$results[1],huang.result3$results[1],huang.result4$results[1],
                                             berinsky.result1$results[1],berinsky.result2$results[1],berinsky.result3$results[1],berinsky.result4$results[1],
                                             nyhanreifler.result1$results[1],nyhanreifler.result2$results[1],nyhanreifler.result3$results[1],nyhanreifler.result4$results[1],
                                             nyhanetal.result1alt$results[1],nyhanetal.result2alt$results[1],nyhanetal.result3alt$results[1],
                                             clayton.result1$results[1], clayton.result2$results[1], clayton.result3$results[1],
                                             woodporter.result01alt$results[1],woodporter.result02alt$results[1],woodporter.result04alt$results[1],woodporter.result05alt$results[1],
                                             woodporter.result06alt$results[1],woodporter.result07alt$results[1],woodporter.result08alt$results[1],woodporter.result09alt$results[1],
                                             woodporter.result10alt$results[1],woodporter.result11alt$results[1],woodporter.result12alt$results[1],woodporter.result13alt$results[1],
                                             woodporter.result14alt$results[1],woodporter.result15alt$results[1],woodporter.result16alt$results[1],woodporter.result17alt$results[1],
                                             woodporter.result18alt$results[1],woodporter.result19alt$results[1],woodporter.result20alt$results[1],woodporter.result21alt$results[1],
                                             woodporter.result22alt$results[1],woodporter.result23alt$results[1],woodporter.result24alt$results[1],woodporter.result25alt$results[1]),
                                           
                                           c(huang.result1$results[3],huang.result2$results[3],huang.result3$results[3],huang.result4$results[3],
                                             berinsky.result1$results[3],berinsky.result2$results[3],berinsky.result3$results[3],berinsky.result4$results[3],
                                             nyhanreifler.result1$results[3],nyhanreifler.result2$results[3],nyhanreifler.result3$results[3],nyhanreifler.result4$results[3],
                                             nyhanetal.result1alt$results[3],nyhanetal.result2alt$results[3],nyhanetal.result3alt$results[3],
                                             clayton.result1$results[3], clayton.result2$results[3], clayton.result3$results[3],
                                             woodporter.result01alt$results[3],woodporter.result02alt$results[3],woodporter.result04alt$results[3],woodporter.result05alt$results[3],
                                             woodporter.result06alt$results[3],woodporter.result07alt$results[3],woodporter.result08alt$results[3],woodporter.result09alt$results[3],
                                             woodporter.result10alt$results[3],woodporter.result11alt$results[3],woodporter.result12alt$results[3],woodporter.result13alt$results[3],
                                             woodporter.result14alt$results[3],woodporter.result15alt$results[3],woodporter.result16alt$results[3],woodporter.result17alt$results[3],
                                             woodporter.result18alt$results[3],woodporter.result19alt$results[3],woodporter.result20alt$results[3],woodporter.result21alt$results[3],
                                             woodporter.result22alt$results[3],woodporter.result23alt$results[3],woodporter.result24alt$results[3],woodporter.result25alt$results[3]),
                                           
                                           c("Huang 2017 (China)","Huang 2017 (China)","Huang 2017 (China)","Huang 2017 (China)","Berinsky 2017 (US)","Berinsky 2017 (US)","Berinsky 2017 (US)","Berinsky 2017 (US)",
                                             "Nyhan and Reifler 2010 (US)","Nyhan and Reifler 2010 (US)", "Nyhan and Reifler 2010 (US)","Nyhan and Reifler 2010 (US)",
                                             "Nyhan et al. 2019 (US)","Nyhan et al. 2019 (US)", "Nyhan et al. 2019 (US)",
                                             "Clayton et al. 2019 (US)", "Clayton et al. 2019 (US)", "Clayton et al. 2019 (US)",
                                             "Wood and Porter 2019 (US)    ", "Wood and Porter 2019 (US)    ", "Wood and Porter 2019 (US)    ", "Wood and Porter 2019 (US)    ",
                                             "Wood and Porter 2019 (US)    ", "Wood and Porter 2019 (US)    ", "Wood and Porter 2019 (US)    ", "Wood and Porter 2019 (US)    ", "Wood and Porter 2019 (US)    ", "Wood and Porter 2019 (US)    ",
                                             "Wood and Porter 2019 (US)    ", "Wood and Porter 2019 (US)    ", "Wood and Porter 2019 (US)    ", "Wood and Porter 2019 (US)    ", "Wood and Porter 2019 (US)    ", "Wood and Porter 2019 (US)    ", 
                                             "Wood and Porter 2019 (US)    ", "Wood and Porter 2019 (US)    ", "Wood and Porter 2019 (US)    ", "Wood and Porter 2019 (US)    ",
                                             "Wood and Porter 2019 (US)    ", "Wood and Porter 2019 (US)    ", "Wood and Porter 2019 (US)    ", "Wood and Porter 2019 (US)    ")  ))

colnames(correction_data_alt) <- c("d","se_d","study")

correction_data_alt$study <- as.character(correction_data_alt$study)
correction_data_alt$d <- as.numeric(as.character(correction_data_alt$d))
correction_data_alt$se_d <- as.numeric(as.character(correction_data_alt$se_d))

#random effects
meta.re_alt <- rma.mv(d,(se_d)^2, 
                  random = list(~ 1 | as.numeric(as.factor(study))), 
                  tdist = TRUE, 
                  slab = study,
                  data = correction_data_alt)

forest(meta.re_alt,
       showweights = TRUE,
       cex=0.8)

